//
//  BYCashierController.m
//  OCDemo
//
//  Created by zhumuzhi on 2022/2/17.
//

#import "BYCashierController.h"

#import "BYCashierTypeView.h"

@interface BYCashierController ()

@property (nonatomic, strong) BYCashierTypeView *aliView;
@property (nonatomic, strong) BYCashierTypeView *weChatView;
@property (nonatomic, strong) UIButton          *affirmPay;


// 记录选择支付类型
@property (nonatomic, assign) BYCashierType payType;

@end

@implementation BYCashierController

#pragma mark - Event
- (void)affirmPayEvent {
    NSLog(@"确认支付事件");
}

#pragma mark - LifeCycle
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = BACKGROUND_VIEW_COLOR;
    
    // 默认为支付宝支付
    self.payType = BYCashierTypeAli;
    [self.view addSubview:self.aliView];
    [self.aliView selectedMethod];
    [self.view addSubview:self.weChatView];
    [self.view addSubview:self.affirmPay];
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    [self.aliView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(kAutoWithSize(10));
        make.left.equalTo(self.view).offset(kAutoWithSize(10));
        make.right.equalTo(self.view).offset(-kAutoWithSize(10));
        make.height.mas_equalTo(kAutoWithSize(80));
    }];
    
    [self.weChatView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.aliView.mas_bottom).offset(kAutoWithSize(10));
        make.left.equalTo(self.view).offset(kAutoWithSize(10));
        make.right.equalTo(self.view).offset(-kAutoWithSize(10));
        make.height.mas_equalTo(kAutoWithSize(80));
    }];
    
    [self.affirmPay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(kAutoWithSize(10));
        make.right.equalTo(self.view).offset(-kAutoWithSize(10));
        make.height.mas_equalTo(kAutoWithSize(50));
        make.bottom.equalTo(self.view.mas_bottom).offset(-kAutoWithSize(100));
    }];
}

#pragma mark - LazyGet

- (BYCashierTypeView *)aliView {
    if (!_aliView) {
        _aliView = [[BYCashierTypeView alloc] init];
        _aliView.payType = BYCashierTypeAli;
        WS(weakSelf)
        _aliView.selectedBlock = ^(BYCashierType payType) {
            [weakSelf.weChatView unSelectedMethod];
            [weakSelf.aliView selectedMethod];
            weakSelf.payType = payType;
        };
    }
    return _aliView;
}

- (BYCashierTypeView *)weChatView {
    if (!_weChatView) {
        _weChatView = [[BYCashierTypeView alloc] init];
        _weChatView.payType = BYCashierTypeWechat;
        WS(weakSelf)
        _weChatView.selectedBlock = ^(BYCashierType payType) {
            [weakSelf.aliView unSelectedMethod];
            [weakSelf.weChatView selectedMethod];
            weakSelf.payType = payType;
        };
    }
    return _weChatView;
}

- (UIButton *)affirmPay {
    if (!_affirmPay) {
        _affirmPay = [[UIButton alloc] init];
        [_affirmPay setTitle:@"确认支付" forState:UIControlStateNormal];
        [_affirmPay setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_affirmPay setBackgroundColor:PUBLIC_ORANGE_COLOR forState:UIControlStateNormal];
        [_affirmPay setBackgroundColor:PUBLIC_ORANGE_COLOR forState:UIControlStateSelected];
        [_affirmPay setViewCornerRadius:kAutoWithSize(8)];
        [_affirmPay addTarget:self action:@selector(affirmPayEvent) forControlEvents:UIControlEventTouchUpInside];
    }
    return _affirmPay;
}



@end
